package com.captain.special.二叉树;

import com.captain.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/4/22 15:02
 */
public class 二叉树的后序遍历145 {
    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        traverse(root,res);
        return res;
    }

    public void traverse(TreeNode node, List<Integer> res) {
        if (node == null) {
            return;
        }
        traverse(node.left, res);
        traverse(node.right, res);
        int val = node.val;
        res.add(val);
    }
}
